﻿Imports System.Data

Public Class FormTipoProdListado

    Dim classController As New Class_RC_Controller.rc_Mantenimiento()

    Private m_frmTipoProd As FrmTipoProd
    Public Property frmTipoProd() As FrmTipoProd
        Get
            Return m_frmTipoProd
        End Get
        Set(value As FrmTipoProd)
            m_frmTipoProd = value
        End Set
    End Property

    Private Sub FormTipoProdListado_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        dgTiposProductos.AutoGenerateColumns = False

        CargarTiposProducto()

    End Sub

    Private Sub CargarTiposProducto()

        Dim dt As New DataTable
        dt = classController.get_TiposProducto_All(oiml.dbConn, 0, txtDescripcion.Text)
        dgTiposProductos.DataSource = dt

    End Sub

    Private Sub btnCancelar_Click(sender As System.Object, e As System.EventArgs) Handles btnCancelar.Click
        Me.Close()

    End Sub

    Private Sub btnEditar_Click(sender As System.Object, e As System.EventArgs) Handles btnEditar.Click
        Try
            If dgTiposProductos.SelectedRows.Count > 0 Then
                Dim codTipoProd As New Integer
                codTipoProd = dgTiposProductos.SelectedRows(0).Cells(0).Value

                If frmTipoProd Is Nothing Then
                    frmTipoProd = New FrmTipoProd
                    frmTipoProd.codTipoProducto = codTipoProd
                    'If frmServicios.ShowDialog() = Windows.Forms.DialogResult.OK Then
                    frmTipoProd.ShowDialog()
                    CargarTiposProducto()
                    frmTipoProd.Dispose()
                    frmTipoProd = Nothing
                    'End If
                Else
                    frmTipoProd.codTipoProducto = codTipoProd
                    frmTipoProd.ShowDialog()
                End If

            End If

        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Sub

    Private Sub txtBuscar_Click(sender As System.Object, e As System.EventArgs) Handles txtBuscar.Click

        CargarTiposProducto()

    End Sub

    Private Sub txtDescripcion_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles txtDescripcion.KeyDown
        If e.KeyCode = Keys.Enter Then
            CargarTiposProducto()

        End If
    End Sub

    Private Sub dgTiposProductos_DoubleClick(sender As System.Object, e As System.EventArgs) Handles dgTiposProductos.DoubleClick
        btnEditar_Click(sender, e)
    End Sub

    Private Sub dgTiposProductos_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles dgTiposProductos.KeyDown
        If e.KeyCode = Keys.Enter Then
            btnEditar_Click(sender, e)
        End If

    End Sub

    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

    End Sub

    Private Sub btnNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNuevo.Click
        '    If frmciudad Is Nothing Then
        frmTipoProd = New FrmTipoProd()
        frmTipoProd.ShowDialog()
        CargarTiposProducto()
        dgTiposProductos.Refresh()
    End Sub

    Private Sub txtDescripcion_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDescripcion.TextChanged

    End Sub
End Class